#!/bin/bash
export 'PS4=[`date +"%Y-%m-%d %H:%M:%S"`]`basename $0`.$LINENO+ '

set -ue
#add timestamps for each output
#STARTTIME=`perl -e 'print time()'`
#exec 1> >(exec -a 'build logging' perl -e '$|=1;select(F);$|=1;while(<STDIN>){my $p=sprintf("[%5ds] ", time()-'$STARTTIME');print STDOUT $p.$_;}') 2>&1

export DEBUG=1
export CPATH=`pwd`
export TOOLS="$CPATH/tools"
export HOME="/root"
export ERROR_LOG="$CPATH/error_log"
export version=

#load the configure
. config.sh || exit 1
if echo "$CI_PROJECT" | grep '_gcov'; then
     modify_for_gcov $CPATH
     . config.sh || exit 1
fi

if [ $ISCI -ne 0 ];then
    export MOUNTDIR_MASTER="//$ICP_CI_IP/mount_for_linux"
    export MOUNTDIR_AGENT="/home/mount_for_linux"
    export MASTER_USER="Administrator"
    export MASTER_PASSWD="EulerOS_123"
else
    export PROJECT_PATH="$WORK_DIR/tmp"
fi

export EULEROS_CHROOT_PATH=/usr1/euleros

HTTP_DIR="/srv/www/htdocs"
PRE_VERSION='internal_use_only/EulerOS/EulerOS_V200R008C00'
set +u
if [ "x${team_from_jenkins}" != "x" ]; then
    PRE_VERSION="internal_use_only/EulerOS_${team_from_jenkins}/EulerOS_V200R008C00"
fi
set -u
VERSION="$CI_PROJECT"
TYPE="Release"
export PRODUCTS="PANGEA EULEROS_BASIC N9000 CSP DORADO Atlas_ai CE cgp_disk cgp_mem"
export SCRIPT=""
export exclude_register_script=('set_release_dir' 'make_docker_image_remote' 'make_vm_qcow2_main' 'make_upgrade_patch')

. common_function.sh || exit 1


function usage()
{
    echo "`basename $0` [script_name|all]"
}

export all_scripts=('set_release_dir' 'build_and_wait' 'make_tar'  'make_debug_tools' 'make_other_tools')
[[ $DEBUG -eq 1 ]] && set -x

check_env
#repodata_check

arg1=$1
shift
arg2=$@
if [ $arg1 == 'all' -o -z $arg1 ]; then
    run_script_all
else
    run_script $arg1 $arg2
fi
